public class TestMultiThread {
    public static void main(String[] args) {
        MixedOrder mo = new MixedOrder();
        Thread t1;
        t1 = new Thread(() -> {
            mo.writer();
            Thread t2;
            t2 = new Thread(mo::read);
            t2.start();
        });

        t1.start();

    }


}

class MixedOrder {
    int a = 0;
    boolean flag = false;

    public void writer() {
        a = 1;
        flag = true;
        System.out.println("a is " + a);
    }

    public void read() {
        if (flag) {
            int i = a + 1;
            System.out.println("i is " + i);
        }
    }
}
